package com.toocms.jinjuhang.dialog.options

import androidx.databinding.ObservableBoolean
import androidx.databinding.ObservableField
import com.toocms.tab.binding.command.BindingAction
import com.toocms.tab.binding.command.BindingCommand

class OptionsItemModel(val viewModel: OptionsModel, val option: OptionsItem) {
    val titleObservableField = ObservableField<CharSequence>()

    val isSelectedObservableBoolean = ObservableBoolean(false)

    val itemClickBindingCommand = BindingCommand<BindingAction>(BindingAction {
        if (viewModel.isShowConfirmObservableBoolean.get()) {
            viewModel.selectedOptions=option
            viewModel.items.forEach {
                it.isSelectedObservableBoolean.set(this@OptionsItemModel == it)
            }
        } else {
            viewModel.dialog?.dismiss()
            viewModel.dialog?.onOptionClickListener?.invoke(option, viewModel.dialog.tag)
        }
    })

    init {
        titleObservableField.set(option.title())
    }
}